package org.tloss.web.editor.form.editors.command;

import org.eclipse.core.resources.IResourceChangeListener;
import org.tloss.web.editor.model.command.Assign;
import org.tloss.web.editor.model.command.Command;
import org.tloss.web.editor.model.command.Else;
import org.tloss.web.editor.model.command.If;
import org.tloss.web.editor.model.command.LoadEnity;
import org.tloss.web.editor.model.command.Replace;
import org.tloss.web.editor.model.command.Reply;

public class ElementFactory {
	public static AbstractCommandElement getInstance(
			AbstractCommandElement parent, Command command,
			IResourceChangeListener listener) {
		if (command instanceof Reply) {
			ReplyElement replyElement = new ReplyElement((Reply) command,
					listener);
			replyElement.setParent(parent);
			return replyElement;
		} else if (command instanceof If) {
			IfElement element = new IfElement((If) command, listener);
			element.setParent(parent);
			return element;
		} else if (command instanceof Else) {
			ElseElement element = new ElseElement((Else) command, listener);
			element.setParent(parent);
			return element;
		} else if (command instanceof Assign) {
			AssignElement element = new AssignElement((Assign) command,
					listener);
			element.setParent(parent);
			return element;
		} else if (command instanceof Replace) {
			ReplaceElement element = new ReplaceElement((Replace) command,
					listener);
			element.setParent(parent);
			return element;
		} else if (command instanceof LoadEnity) {
			LoadEnityElement element = new LoadEnityElement((LoadEnity) command,
					listener);
			element.setParent(parent);
			return element;
		}

		return null;
	}
}
